package com.nectech.entity;

import com.nectech.client.MapleStoryClient;
import com.nectech.util.ImageUtil;

import java.awt.*;

/**
 * @Author: 浅小北
 * @ClassName: Power
 * @Description: 伤害值显示类
 * @Date: 2021/1/30 9:47
 * @Since: version-1.0
 */
public class Power extends AbstractMapleStoryObject{
    public static Image[] images = new Image[10];
    static {
        for (int i = 0; i < images.length; i++) {
            images[i] = ImageUtil.getImage("power_" + i);
        }
    }
    public MapleStoryClient msc;
    public Power() {
        this.speed = 5;

    }

    /**
     * Power类定义一个value值，解决多个Power对象伤害值是定值的问题
     * 保证每个Power对象的value都是自己独有的属性值
     */
    public int value;
    public Power(MapleStoryClient msc,int x,int y) {
        this();
        this.msc = msc;
        this.x = x;
        this.y = y;
        this.value = msc.hero.hitValue;
        this.live = true;
    }

    /**
      * @Author: 浅小北
      * @Description: 显示伤害值
      * @Date: 9:50 2021/1/30
      * @Param:
      * @return:
      */
    @Override
    public void draw(Graphics g) {
        if (!live) {
            msc.powerList.remove(this);
        }
        /*Font f = g.getFont();
        g.setFont(new Font("微软雅黑",Font.BOLD,30));
        g.drawString(this.value + "",x,y);
        g.setFont(f);*/
        drawValue(g);
        move();
    }

     /**
      * @Author: 浅小北
      * @Description: 画数值图片的方法
      * @Date: 10:33 2021/1/30
      * @Param:
      * @return:
      */
     public void drawValue(Graphics g) {
         int power = this.value;
         if (power >= 9999) {
             power = 9999;
         }
         int units = power % 10;
         power = power / 10;
         int tens = power % 10;
         power = power / 10;
         int hundreds = power % 10;
         power = power / 10;
         int thousands = power;
         if (thousands == 0 && hundreds == 0 && tens == 0) {
             //只画个位
             g.drawImage(images[units],x,y - 10,null);
         }
         if (thousands == 0 && hundreds == 0 && tens != 0) {
             //画个位和十位
             g.drawImage(images[tens],x,y,null);
             g.drawImage(images[units],x + 38,y - 10,null);
         }
         if (thousands == 0 && hundreds != 0) {
             //画个位、十位和百位
             g.drawImage(images[hundreds],x,y - 10,null);
             g.drawImage(images[tens],x + 38,y,null);
             g.drawImage(images[units],x + 38 * 2,y,null);
         }
         if (thousands != 0 ) {
             //画个位、十位、百位和千位
             g.drawImage(images[thousands],x,y,null);
             g.drawImage(images[hundreds],x + 38,y - 10,null);
             g.drawImage(images[tens],x + 38 * 2,y,null);
             g.drawImage(images[units],x + 38 * 3,y - 10,null);
         }

     }
     /**
      * @Author: 浅小北
      * @Description: 重写move方法，让伤害数值往上走 
      * @Date: 10:00 2021/1/30
      * @Param: 
      * @return: 
      */
    @Override
    public void move() {
        if (this.y <= 300){
            this.live = false;
        }
        this.y -= speed;
    }
}
